package com.iwhalecloud.bss.kite.cucc.service.pos.bcmc.handler.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.iwhalecloud.bss.kite.common.constant.ErrorConsts;
import com.iwhalecloud.bss.kite.common.util.KiteListUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.client.dto.pos.KitePosDeveloperDTO;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalKeyConsts;
import com.iwhalecloud.bss.kite.cucc.service.pos.bcmc.BcmcPosContext;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteSceneInst;
import com.ztesoft.bss.common.util.SpringUtil;

/**
 * <Description> <br>
 * 组装报文发展人信息节点
 * 
 * @author XXZ<br>
 * @version 1.0<br>
 * @taskId <br>
 * @CreateDate 2020年12月15日 <br>
 * @since R9.0<br>
 * @see com.iwhalecloud.bss.kite.cucc.service.pos.bcmc.handler.impl <br>
 */
@Service
public class BcmcPosDeveloperHandler extends AbstractBcmcPosHandler {

    @Override
    public void doHandle(BcmcPosContext context) {
        IQuerySceneInstService querySceneInstService = SpringUtil.getBean(IQuerySceneInstService.class);
        KiteSceneInst kiteSceneInst = querySceneInstService.getSceneInst(context.getSceneInstId());
        if (StringUtils.equalsAny(kiteSceneInst.getOperType(), LocalKeyConsts.SCENE_OPER_TYPE_ORDER_SIGN,
            LocalKeyConsts.SCENE_OPER_TYPE_TRANSFER_PLAN_MODIFY)) {
            return;
        }
        List<KiteAttr> developerAttrs = querySceneInstService.listCommonAttrsByModuleId(context.getSceneInstId(),
            LocalKeyConsts.MODULE_ID_DEVELOPER);
        // List<KiteAttr> developerAttrs = querySceneInstService.listCommonAttrs(context.getSceneInstId(),
        // LocalKeyConsts.DEVPERSON_OBJECT_TYPE);
        if (KiteListUtils.isEmpty(developerAttrs)) {
            ErrorConsts.BUSI_COMMON_ERROR.throwOut("未配置【发展人】属性");
        }
        KitePosDeveloperDTO developer = new KitePosDeveloperDTO();
        developer.setStaffId(this.getAttrValue(developerAttrs, LocalKeyConsts.DEVPERSON_INFO_ID, "未配置【发展人员工ID】属性"));
        developer
            .setChannelId(this.getAttrValue(developerAttrs, LocalKeyConsts.DEVPERSON_INFO_CHANNELID, "未配置【发展人渠道ID】属性"));
        developer.setChannelName(
            this.getAttrValue(developerAttrs, LocalKeyConsts.DEVPERSON_INFO_CHANNELNAME, "未配置【发展人渠道名称】属性"));
        developer.setName(this.getAttrValue(developerAttrs, LocalKeyConsts.DEVPERSON_INFO_NAME, "未配置【发展人名称】属性"));
        developer.setPhone(this.getAttrValue(developerAttrs, LocalKeyConsts.DEVPERSON_INFO_TEL, "未配置【发展人联系方式】属性"));
        String isSendSms = this.getAttrValue(developerAttrs, LocalKeyConsts.DEVPERSON_INFO_SENDMESSAGE,
            "未配置【是否发送短信】属性");
        // 【是否发送短信】属性获取为空时默认0-否
        if (KiteStringUtils.isEmpty(isSendSms)) {
            developer.setIsSendSms("0");
        }
        else {
            developer.setIsSendSms(isSendSms);
        }
        context.getPosDto().setDeveloper(developer);

    }

}
